<?php
/**
 * Created by PhpStorm.
 * User: 悟能科技
 * Date: 2018/6/7
 * Time: 20:56
 */

namespace app\common\controller;


use app\common\model\CardRank;
use think\Controller;

class CardApizk extends Controller
{

    //API PAY / ANDPAY  CARDPAY 等级折扣
    /*
     * $cardus   discount   is_cz_dj_discount  is_cz_discount
     * $user  card_id   bonus
     * $arr  price
     *
     *
     * 返回
     * $arrs    del_balance    dis_card_zk  vip_card_zk
     *
     *
     *
     */
    public function rankzk($cardus,$user,$arr){
        //判断是否折扣开关
        if ($cardus['is_cz_discount'] == 1 && $cardus['discount'] > 0) {
            $discount = $cardus['discount'] / 100;                  //折扣比率
            $arrs['del_balance'] = $arr['price'] * $discount;     //需回传的支付金额
            $arrs['dis_card_zk'] = $arr['price'] - $arrs['del_balance'];     //会员卡折扣金额
        }else{
            $discount = 1;
            $arrs['del_balance'] = $arr['price'] * $discount;     //需回传的支付金额
            $arrs['dis_card_zk'] = $arr['price'] - $arrs['del_balance'];     //会员卡折扣金额
        }
        $dis_h = $arrs['del_balance'];          //折扣后金额
        //判断等级折扣开关
        if ($cardus['is_cz_dj_discount'] == 1) {
            $card_id = $user['card_id'];
            $level = getlive($card_id, $user['bonus']);
            $CardRank = new CardRank();
            $rankinfo = $CardRank->where(['card_id' => $card_id, 'live' => $level])->find();
            //判断该等级是否折扣
            if ($rankinfo['discount'] > 0) {
                $rankdis = $rankinfo['discount'] / 100;
                $arrs['del_balance'] = $arrs['del_balance'] * $rankdis;     //需回传的支付金额
                $arrs['vip_card_zk'] = $dis_h - $arrs['del_balance'];       //等级折扣金额
            }else{
                $arrs['vip_card_zk'] = 0;       //等级折扣金额
            }
        }else{
            $arrs['vip_card_zk'] = 0;       //等级折扣金额
        }
        return $arrs;
    }


}